﻿using System;
using System.Diagnostics;

namespace Project4_LargestPalindrome {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine("Project Euler Problem 3: What is the largest prime factor of the number 600851475143?");
            Stopwatch timer = new Stopwatch();

            const int LIMIT = 999;

            int biggest = 0;

            for (int term1 = 1; term1 <= LIMIT; term1++) {
                for (int term2 = 1; term2 <= LIMIT; term2++) {
                    int result = term1 * term2;

                    string reversedNumber = string.Empty;
                    foreach (char character in result.ToString().ToCharArray()) {
                        reversedNumber = character + reversedNumber;
                    }

                    if (result.ToString() == reversedNumber) {
                        if (biggest < result) {
                            biggest = result;
                        }
                    }
                }
            }

            timer.Stop();
            Console.WriteLine("\nAnswer: {0}\nin {1}ms ({2} ticks)", biggest, timer.ElapsedMilliseconds, timer.ElapsedTicks);
            Console.WriteLine("\nPress RETURN to exit...");
            Console.ReadLine();
        }
    }
}
